from app.configs.default import Config
import datetime


class LocalConfig(Config):
    DEBUG = True
    SQLALCHEMY_ECHO = False

    REDIS_HOST = 'localhost'
    REDIS_PORT = 6379
    REDIS_DBID = 0
    REDIS_PASSWORD = '123456'

    SQLALCHEMY_CG_URI = 'mysql+pymysql://root:BIci123456_@122.112.158.17:3308/cg_dev'
    SQLALCHEMY_MYSQL_ONLINE_DATABASE_URI = 'mysql+pymysql://root:Cisco123@localhost:3306/ironman'

    KAFKA_SERVERS = ['139.9.160.196:9092', '139.9.160.196:9093', '139.9.160.196:9094']

    SQLALCHEMY_BINDS = {
        'serve_engine': SQLALCHEMY_MYSQL_ONLINE_DATABASE_URI,
        'cg': SQLALCHEMY_CG_URI
    }

    ENABLE_KAFKA = False

    # APScheduler 配置

    # 控制所有定时任务的开启
    SCHEDULE_SWITCH = False
    SCHEDULER_API_ENABLED = False
    GAOLU_BANBIE_BACKTRACKING_ENABLED = False        # 高炉打分数据回溯定时
    HANFAN_DUMP_DATA_ENABLED = True  # 含钒原燃料数据查询定时

    # simulation 还需要设置 deamon.py 里面的具体时间节点
    SHAOJIE_SIMULATION_ENABLED = False
    GAOLU_SIMULATION_ENABLED = False
    HANFAN_SIMULATION_ENABLED = False

    # 秒级别
    if GAOLU_SIMULATION_ENABLED:
        GAOLU_INTERVAL = 5
    else:
        GAOLU_INTERVAL = 3600  # 1 小时

    if SHAOJIE_SIMULATION_ENABLED:
        SHAOJIE_INTERVAL = 5
    else:
        SHAOJIE_INTERVAL = 5

    # 秒级别
    if HANFAN_SIMULATION_ENABLED:
        HANFAN_INTERVAL = 5
    else:
        HANFAN_INTERVAL = 3600  # 1 小时

    HANFAN_DUMP_DATA_INTERVAL = 1800    # 30分钟

    # cron表达式
    GAOLU_BANBIE_SCORE_BACKTRACKING = "0,8,16"

    JOBS = []
    if SCHEDULE_SWITCH:
        JOBS.append({
            'id': 'shaojie_model_predict_online',
            'func': 'app.services.schedule.deamon:shaojie_model_predict_online',
            'trigger': 'interval',
            'seconds': SHAOJIE_INTERVAL
        })
        JOBS.append(
        {
            'id': 'gaolu_model_predict',
            'func': 'app.services.schedule.deamon:gaolu_model_predict_online',
            'trigger': 'interval',
            'seconds': GAOLU_INTERVAL,
            'next_run_time': datetime.datetime.now() + datetime.timedelta(seconds=10)  # job在2分钟后立即运行

        })
        JOBS.append(
            {
                'id': 'hanfan_model_predict',
                'func': 'app.services.schedule.deamon:hanfan_model_predict_online',
                'trigger': 'interval',
                'seconds': HANFAN_INTERVAL,
                'next_run_time': datetime.datetime.now() + datetime.timedelta(seconds=120)  # job在2分钟后立即运行
            })

    if SHAOJIE_SIMULATION_ENABLED:
        JOBS.append(
            {
                'id': 'shaojie_data_stream_simulate',
                'func': 'app.services.schedule.deamon:shaojie_demo_data_stream',
                'args': (),
                'trigger': 'interval',
                'seconds': SHAOJIE_INTERVAL
            }
        )

    if GAOLU_SIMULATION_ENABLED:
        JOBS.append(
            {
                'id': 'gaolu_data_stream_simulate',
                'func': 'app.services.schedule.deamon:gaolu_demo_data_stream',
                'args': (),
                'trigger': 'interval',
                'seconds': GAOLU_INTERVAL
            }
        )

    if GAOLU_BANBIE_BACKTRACKING_ENABLED:
        JOBS.append(
            {
                'id': 'gaolu_banbie_backtracking_data',
                'func': 'app.services.schedule.deamon:gaolu_banbie_backtracking_data',
                'args': (),
                'trigger': 'cron',
                'hour': GAOLU_BANBIE_SCORE_BACKTRACKING
            }
        )

    if HANFAN_DUMP_DATA_ENABLED:
        JOBS.append(
            {
                'id': 'dump_hanfan_data',
                'func': 'app.services.schedule.deamon:dump_hanfan_data',
                'trigger': 'interval',
                'seconds': HANFAN_DUMP_DATA_INTERVAL,
                'args': (datetime.datetime.now(),),
                'next_run_time': datetime.datetime.now() + datetime.timedelta(minutes=10)  # job在10分钟后立即运行
            }
        )
